# !/usr/bin/env python
# encoding: utf-8
# @File    : create_new_thread_dialog.py
# @Time    : 2021/1/31
# @Author  : qiaowei
# @Version : 1.0
# @Email   : weiweiqiao@126.com
# @License : (C) Copyright 2013-2021
# @Brief   : 创建窗体，点击按钮后在console中打印子线程id，对比主线程id


from PySide2.QtCore import Signal
from PySide2.QtCore import QThread
from PySide2.QtWidgets import QDialog
from form.create_new_thread_ui import Ui_Dialog
from multithread.worker import Worker


class Dialog(QDialog):
    def __init__(self):
        super(Dialog, self).__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        print('Dialog.__init__ = ' + str(self.thread()))

        self.__worker = Worker()
        self.__thread = QThread()

        self.__init_connections()

    def __init_connections(self):
        """
        创建信号槽，将对象移入子线程，并启动子线程

        """
        self.ui.create_new_thread_pushButton.clicked.\
            connect(self.__worker.print_thread_id)
        self.__worker.moveToThread(self.__thread)
        self.__thread.start()

    signal_thread = Signal()
